﻿using System.IO;
using System.Text;
using System.Web;

namespace Restful.Net
{
    /// <summary>
    /// Wrapper class around a HttpResponseBase object.
    /// contains the bare necessities to manipulate the response object.
    /// </summary>
    internal class RestResponse : IResponse
    {
        /// <summary>
        /// Response object that is being wrapped.
        /// </summary>
        private readonly HttpResponseBase httpResponse;

        /// <summary>
        /// Initializes a new instance of the <see cref="RestResponse"/> class.
        /// </summary>
        /// <param name="httpResponse">The HTTP response.</param>
        internal RestResponse(HttpResponseBase httpResponse)
        {
            this.httpResponse = httpResponse;
        }

        /// <summary>
        /// Gets the base response.
        /// </summary>
        public HttpResponseBase BaseResponse
        {
            get
            {
                return httpResponse;
            }
        }

        /// <summary>
        /// Gets the output stream used to write data to the client
        /// </summary>
        public Stream OutputStream
        {
            get
            {
                return BaseResponse.OutputStream;
            }
        }

        /// <summary>
        /// Gets or sets the status code of the http response
        /// </summary>
        public int StatusCode
        {
            get
            {
                return BaseResponse.StatusCode;
            }

            set
            {
                BaseResponse.StatusCode = value;
            }
        }

        /// <summary>
        /// Gets or sets the status description.
        /// </summary>
        public string StatusDescription
        {
            get
            {
                return BaseResponse.StatusDescription;
            }

            set
            {
                BaseResponse.StatusDescription = value;
            }
        }

        /// <summary>
        /// Gets or sets the content type of the response.
        /// </summary>
        public string ContentType
        {
            get
            {
                return BaseResponse.ContentType;
            }

            set
            {
                BaseResponse.ContentType = value;
            }
        }

        /// <summary>
        /// Gets or sets the content encoding of the response.
        /// </summary>
        public Encoding ContentEncoding
        {
            get
            {
                return BaseResponse.ContentEncoding;
            }

            set
            {
                BaseResponse.ContentEncoding = value;
            }
        }

        /// <summary>
        /// Gets or sets the Etag that is being used by browsers and proxies to help in caching
        /// </summary>
        public string ETag
        {
            get 
            {
                return BaseResponse.Headers["ETag"];
            }

            set 
            {
                BaseResponse.Headers["ETag"] = value;
            }
        }
    }
}
